package com.wang.wx.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.cache.MapCache;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.wang.wx.entity.sout.*;
import com.wang.wx.listener.*;
import com.wang.wx.service.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;

@Service
public class IOExcelImpl implements IOExcel {
    
    @Resource
    private TwitterUserService twitterUserService;
    @Resource
    private WxUserService wxUserService;
    @Resource
    private EmailUserService emailUserService;
    @Resource
    private LyUserService lyUserService;

    @Value("${path.output}")
    private String outputFilePath;
    
    @Value("${excel.headRowNumber:1}")
    private int headRowNumber;

    /**
     * 邮箱转推特
     * @param inputput
     * @param originalFilename
     */
    @Override
    public void emailToTwitterInputExcel(InputStream inputput, String originalFilename) {
        ExcelReader build = EasyExcel.read(inputput, EmailToTwitterModel.class, new EmailToTwitterExcelDataListener(twitterUserService, outputFilePath + originalFilename)).readCache(new MapCache()).headRowNumber(headRowNumber).build();
        ReadSheet sheet1 = EasyExcel.readSheet("Sheet1").build();
        build.read(sheet1);

    }

    /**
     * 手机转微信
     * @param inputStream
     * @param originalFilename
     */
    @Override
    public void phoneToWxInputExcel(InputStream inputStream, String originalFilename) throws IOException, InterruptedException {
        ExcelReader build = EasyExcel.read(inputStream, PhoneToWxModel.class, new PhoneToWxExcelDataListener(wxUserService, outputFilePath + originalFilename)).readCache(new MapCache()).headRowNumber(headRowNumber).build();
        ReadSheet sheet1 = EasyExcel.readSheet("Sheet1").build();
        build.read(sheet1);
    }

    /**
     * 手机转邮箱
     * @param inputStream
     * @param originalFilename
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public void phoneToEmailInputExcel(InputStream inputStream, String originalFilename) throws IOException, InterruptedException {
        ExcelReader build = EasyExcel.read(inputStream, PhoneToEmailModel.class, new PhoneToEmailExcelDataListener(emailUserService, outputFilePath + originalFilename)).readCache(new MapCache()).headRowNumber(headRowNumber).build();
        ReadSheet sheet1 = EasyExcel.readSheet("Sheet1").build();
        build.read(sheet1);
    }

    /**
     * 手机转领英账号
     * @param inputStream
     * @param originalFilename
     */
    @Override
    public void phoneToLyInputExcel(InputStream inputStream, String originalFilename) {
        ExcelReader build = EasyExcel.read(inputStream, PhoneToLyModel.class, new PhoneToLyExcelDataListener(lyUserService, outputFilePath + originalFilename)).readCache(new MapCache()).headRowNumber(headRowNumber).build();
        ReadSheet sheet1 = EasyExcel.readSheet("Sheet1").build();
        build.read(sheet1);
    }


    /**
     * 邮箱转领英账号
     * @param inputStream
     * @param originalFilename
     */
    @Override
    public void emailToLyInputExcel(InputStream inputStream, String originalFilename) {
        ExcelReader build = EasyExcel.read(inputStream, EmailToLyModel.class, new EmailToLyExcelDataListener(lyUserService, outputFilePath + originalFilename)).readCache(new MapCache()).headRowNumber(headRowNumber).build();
        ReadSheet sheet1 = EasyExcel.readSheet("Sheet1").build();
        build.read(sheet1);
    }


}